angular.module('liemallfodder')
  .controller('SubCategoryListCtrl', function ($scope, $stateParams, Toast, Loading, ApiManager, MaterialApi) {

    $scope.subcategories = [];

    var requestListSubCategory = function () {
      var category_id = $stateParams.category_id;
      if (category_id < 0) {
        Toast.show('错误的id');
        return;
      }
      Loading.show('正在加载');
      MaterialApi.listSubCategory(category_id, function (result) {
        Loading.hide();
        if (ApiManager.hasError(result)) {
          return;
        }
        $scope.subcategories = result.data;

      }, function (error) {
        Loading.hide();
        ApiManager.showError(error);
      })
    };

    requestListSubCategory();

  });
